﻿using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using MSP.Data.Domain;

namespace MSP.Data.Maps
{
    public class SalesMap : ClassMapping<Sales>
    {
        public SalesMap()
        {
            Table("[SALES]");
            Schema("dbo");
            Lazy(true);
            Id(x => x.Id,
               map =>
               {
                   map.Generator(Generators.HighLow,
                                 g =>
                                 g.Params(
                                     new { table = "T_NEXT_ID", column = "NEXT_ID", max_lo = "0", where = "type = 'SALES'" }));
                   map.Column("ID");
               });
            Property(x => x.SalesDate, map => map.Column("SALES_DATE"));
            Property(x => x.Price, map => map.Column("PRICE"));
            Property(x => x.Discount, map => map.Column("DISCOUNT"));
            Property(x => x.ReceivedPrice, map => map.Column("RECEIVED_PRICE"));
            Property(x => x.Profit, map => map.Column("PROFIT"));
            Property(x => x.Description, map => map.Column("DESCRIPTION"));
            Property(x => x.DateCreated, map => map.Column("DATE_CREATED"));
            Property(x => x.DateEdited, map => map.Column("DATE_EDITED"));

            ManyToOne(x => x.Customer, map =>
            {
                map.Column("CUSTOMER_ID");
                map.Cascade(Cascade.None);
            });

            ManyToOne(x => x.Cashier, map =>
            {
                map.Column("CASHIER_ID");
                map.Cascade(Cascade.None);
            });

            ManyToOne(x => x.CreatedUser, map =>
            {
                map.Column("CREATED_USER");
                map.Cascade(Cascade.None);
            });

            ManyToOne(x => x.EditedUser, map =>
            {
                map.Column("EDITED_USER");
                map.Cascade(Cascade.None);
            });

        }
    }
}
